# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: loqs
# Contributor: Fredy García <frealgagu at gmail dot com>
# Contributor: Youngbin Han <sukso96100@gmail.com>
# Contributor: blainester <theblainestory@gmail.com>
# Contributor: mar77i <mar77i at protonmail dot ch>

pkgname=micro
pkgver=2.0.13
pkgrel=1
# manually set date instead of "go run tools/build-date.go", for reproducible builds
_build_date='October 22, 2023'
pkgdesc='Modern and intuitive terminal-based text editor'
arch=(loong64 x86_64)
url='https://micro-editor.github.io/'
license=(MIT)
makedepends=(git go)
optdepends=('wl-clipboard: for copying/pasting text using Wayland'
            'xclip: for copying/pasting text using X')
source=("git+https://github.com/zyedidia/micro#commit=68d88b571de6dca9fb8f03e2a3caafa2287c38d4") # tag: v2.0.13
b2sums=('SKIP')

prepare() {
  cd $pkgname
  # Let tools/build-date.go always return the same date, to make the package reproducible
  echo -e '//+build ignore\npackage main\nimport "fmt"\nfunc main() { fmt.Println("'$_build_date'") }' > tools/build-date.go
  # Modify the Go build flags
  sed -i 's/-trimpath/-buildmode=pie -trimpath/g;s/GS)/GS) -linkmode=external -extldflags \\"$(LDFLAGS)\\"/g' Makefile
}

build() {
  make -C $pkgname
}

check() {
  make -C $pkgname test
}

package() {
  cd $pkgname
  install -Dm755 $pkgname "$pkgdir/usr/bin/$pkgname"
  install -Dm644 assets/packaging/micro.1 -t "$pkgdir/usr/share/man/man1"
  install -Dm644 assets/packaging/micro.desktop -t "$pkgdir/usr/share/applications"
  install -Dm644 assets/micro-logo-mark.svg "$pkgdir/usr/share/icons/hicolor/scalable/apps/$pkgname.svg"
  install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE LICENSE-THIRD-PARTY
}
